fix(react): Prevent the operation queue from being flushed during synchronous cache reads #2556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolve #2554
Don't forget to deduplicate
@urql/core
to the newest version if you do upgrade, since its fix is important.During some circumstances we may receive an update that then leads to a mount. React may decide to then recursively & synchronously continue this mount. During it, we used to then block other updates using a
currentInit
flag while the component synchronously reads from the cache. However, since the cache read dispatched its operation (and then terminated), we previously then "piggybacked" off of this dispatch, and flushed other operations.This means that some potential updates could get lost if they were queued up by the update that lead to the mounted component. We instead want to prevent the queue from further being flushed when the synchronous read terminates, and always schedule a microtick that then gets another chance to flush out the queue.
We furthermore prevent recursive calls from restarting our operation queue.
This allows us to remove the
currentInit
check entirely and prevent edge cases from causing missed updates. Such cases would always follow this pattern:The new pattern is now: